package com.cloud.basic.lambda.usage;

import java.util.function.Consumer;

/**
 * 使用Consumer函数式接口实现格式化输出
 */
public class ConsumerDemo2 {

    public static void printInfo(String[] strArr, Consumer<String> con1, Consumer<String> con2){

        // 简单来说，andThen 先执行con1(即当前的函数接口的accept，后执行con2的接口)，参数为accept传进来的值。
        for (int i = 0; i < strArr.length; i++) {
            con1.andThen(con2).accept(strArr[i]);
        }
    }

    public static void main(String[] args) {
        String[] strArr = {"迪丽热巴,女","郑爽,女","杨紫,女"};
        printInfo(strArr,(message)->{
            System.out.print("姓名:" + message.split(",")[0] + "。  ");
        },(message)->{
            System.out.println("性别:" + message.split(",")[1] + "。");

        });
    }
}
